<?php
require 'dbconnect.inc.php';
$a=$_SESSION['annot'];
$b=$_SESSION['id'];
if(isset($_SESSION['emaild']))
$user=$_SESSION['emaild'];
$id=$b[0];
$start=-1;
$end=-1;
$px25='25px';
$px20='20px';

$reslt=mysqli_query($link,"select text from content where id='$id'");
$txt=mysqli_fetch_array($reslt);
echo '<div id="right_panel_text">';
if(mysqli_num_rows($reslt)==0) {echo 'Click on a highlighted text portion to view its annotations!';}
echo '</div>';

for($j=0;$j<count($a);$j++)
{
	  $id=$b[$j];
    $reslt=mysqli_query($link,"select spos,epos,text from content where id='$id'");
    $pos=mysqli_fetch_array($reslt);

    if($start!=$pos['spos'] || $end!=$pos['epos'])
    {
      echo '<h3 class="text_line"></h3><hr style="border" color="black"></hr>';

      echo '<div id="right_panel_text">';
      echo '" '.$pos['text'].'"';
      echo '</div>';
      $start=$pos['spos'];
      $end=$pos['epos'];
    }




    echo '<h3 class="text_line"></h3>
      		<div id="annotationpanel" >';
      echo $a[$j];
      echo '</div>';
      echo '<div id="votepanel">'; 
      echo '<form action="incrmvote.php" method="POST">';
      
      $voteresult=mysqli_query($link,"select * from votes where id='$id' and user='$user'");
      $votenumrows=mysqli_num_rows($voteresult);
      $voterow=mysqli_fetch_array($voteresult);
      
        if($voterow['votetype']==1 && $votenumrows>0 && isset($_SESSION['emaild']))
        {
            echo '<input type="image"  name="submit" value="up" src="static/up.jpg" height="25px" width="25px" style="vertical-align:middle;" ';
            include 'alert.php';
            echo '><br>';
        }
        else
        {
            echo '<input type="image" name="submit" value="up" src="static/up.jpg" height="20px" width="20px" style="vertical-align:middle;" ';
            include 'alert.php';   
            echo '><br>';
        }
          $reslt=mysqli_query($link,"select * from content where id='$id'");
          $row=mysqli_fetch_array($reslt);
        echo '<div id="current_vote">&nbsp;'.$row['votes'].'</div>';
        if($voterow['votetype']==0 && $votenumrows>0 && isset($_SESSION['emaild']))
        { 
            echo '<input type="image" name="submit" value="down" src="static/down.jpg" height="25px" width="25px" style="vertical-align:middle;" ';
            include 'alert.php';  
            echo '><br>';
  		    
        }
      else
      {
  	        echo '<input type="image" name="submit" value="down" src="static/down.jpg" height="20px" width="20px style="vertical-align:middle;" ';
            include 'alert.php';
            echo '><br>';
      }

      echo	'<input  type="hidden" name="hide" value="'.$b[$j].'"> 
      		</form>
      		</div>
            <div id="annotation_property"> Created by '.$row['user'].' on '.$row['date'].'</div>';




}
mysqli_close($link);
?>
